<?php

/**
 * @package Bike
 * @subpackage Db
 */

/**
 * Base interface for database
 * @author Chrome
 * @package Bike
 * @subpackage Db
 */
interface Bike_Db_Idb {
	/**
	 * Constant for setting fetch mode to ASSOC
	 * @var integer
	 */
	const FETCH_RESULT_ASSOC = 1;
	
	/**
	 * Constant for setting fetch mode to NUM
	 * @var integer
	 */
	const FETCH_RESULT_NUM = 2;
	
	/**
	 * Constant fot setting fetch mode to BOTH
	 * @var integer
	 */
	const FETCH_RESULT_BOTH = 3;
	
	/**
	 * Construct object
	 * @param string $dbHost
	 * @param string $dbName
	 * @param string $dbUser
	 * @param string $dbPass
	 * @param array $dbOptions
	 * @param string $initialQuery
	 */
	public function __construct($dbHost, $dbName, $dbUser, $dbPass, array $dbOptions = array(), $initialQuery = '');
	
	/**
	 * Make filters from array
	 * @param array $filters
	 * @return string of filters
	 */
	public function makeFilters(array $filters);
	
	/**
	 * Fetch data from database
	 * @param string $prefix table prefix
	 * @param string $name table name
	 * @param string $filters filters string
	 * @param integer $offset
	 * @param integer $limit
	 * @param array $sortings
	 * @return array
	 */
	public function fetchData($prefix, $name, $filters, $offset, $limit, array $sortings = array());
	
	/**
	 * Update data in database
	 * @param string $prefix table prefix
	 * @param string $name table name
	 * @param integer $id id of record
	 * @param array $data
	 * @return boolean
	 */
	public function update($prefix, $name, $id, array $data);
	
	/**
	 * Insert data into table
	 * @param string $prefix table prefix
	 * @param string $name table name
	 * @param array $data
	 * @return boolean
	 */
	public function insert($prefix, $name, array $data);
	
	/**
	 * Delete record from table
	 * @param string $prefix table prefix
	 * @param string $name name of table
	 * @param integer $id id of record
	 * @return boolean
	 */
	public function delete($prefix, $name, $id);
	
	/**
	 * Send query to database
	 * @param string $query
	 * @param integer $fetchMode
	 * @return cursor(array)
	 */
	public function query($query, $fetchMode = self::FETCH_ASSOC);
}
